#include "stdafx.h"
#include "graph.h"
#include <algorithm>
using std::vector;
using std::set;

void CGraph::Prim(int u) {
	int cV = GetCountV();
	set<int> q; // kolejka priorytetowa wierzcholkow
	set<int> v_q; // wierzcholki budowanego drzewa
	for(int i=0; i<cV; i++) //1...cV 
		q.insert(i+1);
	v_q.insert(u);
	q.erase(u);
	set<edge> edg;
	set<edge> MDR;
	set<edge>::iterator ite;
	int n=0;
	int c_i;
	while(!q.empty())
	{
		vector<int> conseqs = GetConsequents(u);
		for (int i=0; i<conseqs.size(); ++i)
		{
			c_i = conseqs[i];
			if(!(int)count(v_q.begin(),v_q.end(),c_i))
			{
				edge temp;
				temp.vA=u;
				temp.vB=c_i;
				temp.weight=GetWeight(u,c_i);
				edg.insert(temp);
			}
		}
		ite=edg.begin();
		n++;
		u=(*ite).vB;
		if(!v_q.count(u))
		{
			MDR.insert(*ite);
			edg.erase(ite);
			v_q.insert(u);
			q.erase(u);
		}
		else
			edg.erase(ite);
	}

}